<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<?php
include "connection.php";

$user_name = $_REQUEST['user_name'];
//由于新需求，不能中途插入会员号，所以锁定由系统添加
//$user_id = $_REQUEST['user_id'];
$department = $_REQUEST['department'];
$user_term = "0";
$password = md5("123");
$balance = $_REQUEST['balance'];
$account=$_REQUEST['account'];

$tableUser = "user";

$query = mysql_query("select count(nid) from $tableUser where user_id='$user_id'");
$sum = mysql_result($query, 0);
//因为上面不接收客户编写的uid，下面会判断是否已经存在uid,所以sum需要设置为0，程序才能通过
$sum =0;

$table = "user";
$sqlstr="select * from user where user_id=(select max(user_id) from user)";
$result2 = mysql_query($sqlstr);

while ($rows = mysql_fetch_array($result2)) {
    $maxnid = $rows['user_id'];

}

$maxnid=$maxnid+1;


if($sum==0){
    $sql = "insert into $tableUser (
user_name,
user_id,
department,
user_term,
password,
balance
) value (
'$user_name',
'$maxnid',
'$department',
'$user_term',
'$password',
'$balance'
)";
    $query = mysql_query($sql) or die ("添加失败，请返回！");

    ?>

    <script type="text/javascript">
        alert("会员已添加，请点击返回列表！");
        document.location = "../admin_list_control.php";
    </script>


<?

}else{
    ?>

    <script type="text/javascript">
        alert("会员号已存在，请点击返回重新操作！");
        document.location = "../admin_useradd.php";
    </script>


<?
}
?>

</body>
</html>